//
//  StockTableQuote.h
//  iStock Global
//
//  Created by Andy on 2010/10/2.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "StockTableQuoteCell.h"
#import "DataObject.h"
#import "StockGrapth.h"
#import "navcontroller.h"
#import "CustomUIActionSheetViewControllerNxib.h"
#import "DownloadData.h"
#import "editWatchList.h"
#import "StockTableQuoteSetup.h"
#import "HeaderView.h"
#import "ActivityIndicator_view.h"

@protocol StockTableQuoteDelgete
-(void)refreshWatchList;
 
@end


@interface StockTableQuote : UITableViewController <UITableViewDelegate,StockTableQuoteSetupDelgete,UIAlertViewDelegate,editWatchListDelgete,GraphObjectDelgete,DataObjectDelgete ,DownloadDataDelgete,UIActionSheetDelegate,CustomUIActionDelgeteNxib>{
	
    //標記:Drag Refresh HeaderView宣告
    HeaderView* headerView;
    
    id <StockTableQuoteDelgete> delgete;	
	
	NSUInteger  GraphIndex; //正在繪圖的位置
    
    int previous_index;//前一各繪圖位置  //標記: 清除最小股票單位資料物件	 (宣告定義)
	float			amountDone;
	int progresscount;
	BOOL isInOptimize;
	
	UIActionSheet	*baseSheet;	
	BOOL calcuate_stop;
   
	UIProgressView *progressView;
	float progressMax;
	float progressValue;
	
	//UIActivityIndicatorView *ActivityIndicator;	
	
    //標記:進度指示器 宣告(StockTableQuote.h)    
    ActivityIndicator_view *acv;    
    
    BOOL isRuningRefreshQuoteTable;
    BOOL canRuningRefreshQuoteTable;    
    
    NSDate *refresh_quote_time;
    
	UINavigationController *navdelegete;	
	BOOL havefirstusenavcontroller;
	
	BOOL isfirstQuote;
	NSMutableArray *dataSource;

	
	NSMutableArray *temp_data_code;
	    
    NSMutableArray *data_code;
	NSMutableArray *data_name;
    NSMutableArray *data_class;
	NSMutableArray *data_id_class;
    
    
	
	NSString *market; //市場別 也許為自選股
	
	int downhistoryindex;
	 
	//網路資料下載物件
	DownloadData *downloadobject;
	BOOL isDownloadQuoteNow;
	
	
	
	//下載資料細項
	NSMutableArray *download_data;
	//資料物件
	NSMutableArray *download_data_obj;
	
	 
	int HistoryDownloadIndex;
	
	StockGrapth *graph;
	
	//表格高度
	int TableHeigh;
	
	//設定圖表的日期格式 日週月
	NSString *Gdwm;
	//表頭欄位
	NSMutableArray *picka1;
	NSMutableArray *picka2;
	NSMutableArray *picka3;
	//需要計算的表頭欄位指標
	NSMutableArray *needCalcuateTableIndicator;
	
	//表格報價指標
	BOOL isCaluateTableIndicatorNow;
	int Total_CaluateTableIndicator;
	int index_CaluateTableIndicator;	
	NSMutableArray *haveToTableCaluateIndicator;// 必須要在DataObject  進行計算
	
	//表格排訊用
	 int sort_1_index;
	int sort_2_index;	
	int sort_3_index;
	int select_col_index; //選擇哪個欄位
	int select_col_index_row;
	int select_col_index_row_updwon;
	
    id AppleDeglate;
    
    //標記:表格內展開出現日內走勢圖 宣告
    NSMutableArray *expand_table_code; //記錄有哪些表格是展開的
    int tablecell_high_zoom_out; //當表格擴展時的高度
   
    //標記:日內走勢圖記憶體宣告實體與消滅 宣告   
    NSMutableArray *intraday_data_code; //暫存日內資料
    NSMutableArray *intraday_data; //暫存日內資料 
    NSMutableArray *intraday_data_x_time; //所有x軸時間資料    
   
    NSMutableArray *intraday_graph_x_length;// 日內走勢圖的x軸 長度    
    NSMutableArray *intraday_graph_x_high;// 日內走勢圖的x軸 最高價    
    NSMutableArray *intraday_graph_x_low;// 日內走勢圖的x軸 最低價
    
    NSMutableArray *intraday_graph_volume_high;// 日內走勢圖的x軸 最高量    
    NSMutableArray *intraday_graph_volume_low;// 日內走勢圖的x軸 最低量
    NSMutableArray *intraday_graph_lastdayClose;//前一日收盤價    
   
    NSMutableArray *intraday_graph_selected_right;//日內走勢圖的x軸 右邊
    NSMutableArray *intraday_graph_selected_left; //日內走勢圖的x軸 左邊 
    
    
    //如果日內資料陣列以後還有新增 務必到  -(void)Clean_memory_intraday_data 作記憶體清除工作

}
@property (assign) id AppleDeglate;
@property (assign) id <StockTableQuoteDelgete> delgete;

@property (assign) NSMutableArray *data_name;
@property (retain) NSMutableArray *data_class;
@property (retain) NSMutableArray *data_id_class;
@property (retain) NSMutableArray *data_code;
@property (assign) NSString *market;

@property (nonatomic, retain)UIActionSheet *baseSheet;
@property (nonatomic, retain) StockGrapth *graph;
 
 
-(void)refeshTableQuote;
-(void)buttont_refresh:sender;
-(void)sort_table;
-(void)sort_table_col0;
-(void)sort_table_col1;
-(void)sort_table_col2;
-(void)refreshALL:sender;
//-(void)setupCell:(UITableViewCell *)cell forStockAtIndex:(NSUInteger )row ;
-(void)get_navcontroller:(UINavigationController *)nd;
-(void)showSetup;
-(void)presentSheet;
-(void)calculate_stop;
-(void)incrementBara:(NSString *)symbol;
-(void)editWatchList;
-(void)setStockTableQuoteCell:(StockTableQuoteCell *)wcell 
					  identfy:(NSString *)identfy 
					dataobjet:(DataObject *)ob 
				   UILabel_cr:(UILabel *)cr 
				   sortString:(NSString *)sortString;
-(void)calcuate_Table_Indicator;
-(NSString *)Symbol_converTo_timeZoneWithName:(NSString*) symbol;


NSInteger comparator_updownpercent_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_updownpercent_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_updown_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_updown_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Name_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Name_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Symbol_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Symbol_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Class_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Class_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Price_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Price_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Time_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Time_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Date_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Date_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Volume_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_Volume_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_EPSCurrentYear_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_EPSCurrentYear_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_PENextYear_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_PENextYear_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_5DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_5DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_10DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_10DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_20DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_20DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_60DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_60DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_120DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_120DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_240DayChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_240DayChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_WeekChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_WeekChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MonthChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MonthChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_QuarterChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_QuarterChange_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_YearChange_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_YearChange_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_Signal1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Signal1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Signal2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Signal2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Signal3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Signal3_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_BreakP3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_LongDay1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongDay1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongDay2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongDay2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongDay3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongDay3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_ShortgDay1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgDay1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgDay2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgDay2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgDay3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgDay3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_LongProfit1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongProfit1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongProfit2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongProfit2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongProfit3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_LongProfit3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_ShortgProfit1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgProfit1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgProfit2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgProfit2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgProfit3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_ShortgProfit3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_FAMA1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_FAMA1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_FAMA2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_FAMA2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_FAMA3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_FAMA3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_MAMA1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_MAMA1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_MAMA2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_MAMA2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_MAMA3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_MAMA3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_Signal1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Signal1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Signal2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Signal2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Signal3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Signal3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_LF_Action1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Action1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Action2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Action2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Action3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_LF_Action3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_Action1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Action1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Action2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Action2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Action3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_Action3_DOWN( DataObject *d1, DataObject *d2, void *context );



NSInteger comparator_MESA_LongDay1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongDay1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongDay2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongDay2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongDay3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongDay3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_ShortgDay1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgDay1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgDay2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgDay2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgDay3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgDay3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_LongProfit1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongProfit1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongProfit2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongProfit2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongProfit3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_LongProfit3_DOWN( DataObject *d1, DataObject *d2, void *context );

NSInteger comparator_MESA_ShortgProfit1_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgProfit1_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgProfit2_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgProfit2_DOWN( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgProfit3_UP( DataObject *d1, DataObject *d2, void *context );
NSInteger comparator_MESA_ShortgProfit3_DOWN( DataObject *d1, DataObject *d2, void *context );





-(void)incrementBara_CaluateTableIndicator:(NSString *)symbol;
-(void)Clean_memory_intraday_data;

@end
